package com.university.infrastructure;

import com.university.enums.ResultEnum;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class Result<T> {

    /**
     * 代码
     */
    private Integer code;

    /**
     * 消息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    public static <T> Result success(T data) {
        return Result.builder().code(ResultEnum.SUCCESS.getCode()).msg(ResultEnum.SUCCESS.getMessage()).data(data).build();
    }

    public static Result success() {
        return Result.builder().code(ResultEnum.SUCCESS.getCode()).msg(ResultEnum.SUCCESS.getMessage()).build();
    }

    public static Result failure(Integer code, String msg) {
        return Result.builder().code(code).msg(msg).build();
    }
}
